#include "mycaculatedialog.h"
#include <QDoubleValidator>

MyCaculateDialog::MyCaculateDialog()
    :ui(new Ui::CaculateDialog())
{
    ui->setupUi(this);
    ui->lineEdit->setValidator(new QDoubleValidator());
    ui->lineEdit_2->setValidator(new QDoubleValidator());
    ui->pushButton->setEnabled(false);

    this->setFixedHeight(80);

    QObject::connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(enableBtn()));
    QObject::connect(ui->lineEdit_2,SIGNAL(textChanged(QString)),this,SLOT(enableBtn()));
    QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(caculate()));
}

void MyCaculateDialog::enableBtn()
{
    bool b1= false,b2 = false;
    ui->lineEdit->text().toDouble(&b1);
    ui->lineEdit_2->text().toDouble(&b2);

    ui->pushButton->setEnabled(b1 && b2);


}

void MyCaculateDialog::caculate()
{
    double d1 = ui->lineEdit->text().toDouble();
    double d2 = ui->lineEdit_2->text().toDouble();
    double sum = d1 + d2;
    QString str = QString::number(sum);

    ui->lineEdit_3->setText(str);
}
